package com.ruix.app.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.ruix.app.R;
import com.ruix.app.adapter.superadapter.IMulItemViewType;
import com.ruix.app.adapter.superadapter.SuperAdapter;
import com.ruix.app.adapter.superadapter.internal.SuperViewHolder;
import com.ruix.app.model.PostsCard;
import com.ruix.app.model.PostsType;

import java.util.List;

import me.iwf.photopicker.PhotoPreview;

/**
 * Created by hadexs on 2017/5/7.
 */

public class PictureAdapter extends SuperAdapter<String>{

    private PostsCard postsCard;
    private Activity activity;


    public PictureAdapter(Context context, List<String> postsCards, IMulItemViewType<String> mulItemViewType) {
        super(context, postsCards, mulItemViewType);
    }

    @Override
    public void onBind(SuperViewHolder holder, int viewType, int position, String item) {
        if (postsCard == null || activity == null){
            return;
        }

        //图片
        if (viewType == PostsType.POSTS_TYPE_ONE.ordinal()) {
            holder.setSimpleDraweeURI(R.id.iv_pic_one,postsCard.getAlbum().get(0));
            holder.setOnClickListener(R.id.iv_pic_one, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(0)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
        } else if (viewType == PostsType.POSTS_TYPE_TWO.ordinal()) {
            holder.setSimpleDraweeURI(R.id.iv_pic_one,postsCard.getAlbum().get(0));
            holder.setOnClickListener(R.id.iv_pic_one, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //todo
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(0)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setSimpleDraweeURI(R.id.iv_pic_two,postsCard.getAlbum().get(1));
            holder.setOnClickListener(R.id.iv_pic_two, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //todo
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(1)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
        } else if (viewType == PostsType.POSTS_TYPE_THREE.ordinal()) {
            holder.setSimpleDraweeURI(R.id.iv_pic_one,postsCard.getAlbum().get(0));
            holder.setSimpleDraweeURI(R.id.iv_pic_two,postsCard.getAlbum().get(1));
            holder.setSimpleDraweeURI(R.id.iv_pic_three,postsCard.getAlbum().get(2));

            holder.setOnClickListener(R.id.iv_pic_one, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(0)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_two, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(1)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_three, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(2)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });



        } else if (viewType == PostsType.POSTS_TYPE_FOUR.ordinal()) {
            holder.setSimpleDraweeURI(R.id.iv_pic_one,postsCard.getAlbum().get(0));
            holder.setSimpleDraweeURI(R.id.iv_pic_two,postsCard.getAlbum().get(1));
            holder.setSimpleDraweeURI(R.id.iv_pic_three,postsCard.getAlbum().get(2));
            holder.setSimpleDraweeURI(R.id.iv_pic_four,postsCard.getAlbum().get(3));
            holder.setOnClickListener(R.id.iv_pic_one, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(0)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_two, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(1)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_three, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(2)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_four, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(3)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });

        } else if (viewType == PostsType.POSTS_TYPE_FIVE.ordinal()) {
            holder.setSimpleDraweeURI(R.id.iv_pic_one,postsCard.getAlbum().get(0));
            holder.setSimpleDraweeURI(R.id.iv_pic_two,postsCard.getAlbum().get(1));
            holder.setSimpleDraweeURI(R.id.iv_pic_three,postsCard.getAlbum().get(2));
            holder.setSimpleDraweeURI(R.id.iv_pic_four,postsCard.getAlbum().get(3));
            holder.setSimpleDraweeURI(R.id.iv_pic_five,postsCard.getAlbum().get(4));
            if (postsCard.getAlbum().size() == 6){
                holder.setSimpleDraweeURI(R.id.iv_pic_six,postsCard.getAlbum().get(5));
                holder.setVisibility(R.id.iv_pic_six, View.VISIBLE);
                holder.setOnClickListener(R.id.iv_pic_six, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //todo
                        PhotoPreview.builder()
                                .setPhotos(postsCard.getAlbum())
                                .setCurrentItem(5)
                                .setShowDeleteButton(false)
                                .start(activity);
                    }
                });
            } else {
                holder.setVisibility(R.id.iv_pic_six, View.GONE);
            }
            holder.setOnClickListener(R.id.iv_pic_one, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(0)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_two, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(1)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_three, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(2)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_four, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(3)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });

            holder.setOnClickListener(R.id.iv_pic_five, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(4)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });

        } else if (viewType == PostsType.POSTS_TYPE_SIX.ordinal()) {
            holder.setSimpleDraweeURI(R.id.iv_pic_one,postsCard.getAlbum().get(0));
            holder.setSimpleDraweeURI(R.id.iv_pic_two,postsCard.getAlbum().get(1));
            holder.setSimpleDraweeURI(R.id.iv_pic_three,postsCard.getAlbum().get(2));
            holder.setSimpleDraweeURI(R.id.iv_pic_four,postsCard.getAlbum().get(3));
            holder.setSimpleDraweeURI(R.id.iv_pic_five,postsCard.getAlbum().get(4));
            holder.setSimpleDraweeURI(R.id.iv_pic_six,postsCard.getAlbum().get(5));
            holder.setSimpleDraweeURI(R.id.iv_pic_seven,postsCard.getAlbum().get(6));
            if (postsCard.getAlbum().size() == 8){
                holder.setSimpleDraweeURI(R.id.iv_pic_eight,postsCard.getAlbum().get(7));
                holder.setVisibility(R.id.iv_pic_eight, View.VISIBLE);
                holder.setVisibility(R.id.iv_pic_nine, View.GONE);
                holder.setOnClickListener(R.id.iv_pic_eight, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        PhotoPreview.builder()
                                .setPhotos(postsCard.getAlbum())
                                .setCurrentItem(7)
                                .setShowDeleteButton(false)
                                .start(activity);
                    }
                });
            } else if (postsCard.getAlbum().size() == 9){
                holder.setSimpleDraweeURI(R.id.iv_pic_eight,postsCard.getAlbum().get(7));
                holder.setSimpleDraweeURI(R.id.iv_pic_nine,postsCard.getAlbum().get(8));
                holder.setVisibility(R.id.iv_pic_nine, View.VISIBLE);
                holder.setVisibility(R.id.iv_pic_eight, View.VISIBLE);
                holder.setOnClickListener(R.id.iv_pic_eight, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        PhotoPreview.builder()
                                .setPhotos(postsCard.getAlbum())
                                .setCurrentItem(7)
                                .setShowDeleteButton(false)
                                .start(activity);
                    }
                });
                holder.setOnClickListener(R.id.iv_pic_nine, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        PhotoPreview.builder()
                                .setPhotos(postsCard.getAlbum())
                                .setCurrentItem(8)
                                .setShowDeleteButton(false)
                                .start(activity);
                    }
                });
            } else {
                holder.setVisibility(R.id.iv_pic_nine, View.GONE);
                holder.setVisibility(R.id.iv_pic_eight, View.GONE);
            }

            holder.setOnClickListener(R.id.iv_pic_one, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(0)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_two, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(1)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_three, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(2)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_four, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(3)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });

            holder.setOnClickListener(R.id.iv_pic_five, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(4)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_six, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(5)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });
            holder.setOnClickListener(R.id.iv_pic_seven, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PhotoPreview.builder()
                            .setPhotos(postsCard.getAlbum())
                            .setCurrentItem(6)
                            .setShowDeleteButton(false)
                            .start(activity);
                }
            });

        }



    }

    public void setPostsCard(PostsCard postsCard) {
        this.postsCard = postsCard;
    }

    public void setActivity(Activity activity) {
        this.activity = activity;
    }

    public void clearResource(){
        mContext = null;
        postsCard = null;
        activity = null;

    }
}
